package com.example.bitmap;

import java.util.ArrayList;
import java.io.*;
import java.util.Scanner;

public class Teque {
	static ArrayList<Integer> queue = new ArrayList<Integer>();
	static int[] queArray = new int[1024];
	static int rear = 0;
	static int[] temp = new int[]{};

	public int[] push_back(int num1){
	   queArray[rear++]=num1;
	   return queArray;
	}

	public int[] push_front(int num2){
		int[] queArray1 = new int[queArray.length];
		queArray1[0] = num2;
		for(int i=0;i<=rear;i++){
			queArray1[i+1]=queArray[i];
		}
		rear++;
		queArray = queArray1;
		return queArray;
	}

	public int[] push_middle(int num3){
		int[] queArray1 = new int[queArray.length];
		for(int i=0;i<=rear;i++){
			if ((rear+1)/2>i) {
				queArray1[i] = queArray[i];
			}else if ((rear+1)/2==i){
				queArray1[i] = num3;
			}else {
				queArray1[i] = queArray[i-1];
			}
		}
		rear++;
		queArray = queArray1;
		return queArray;
	}

   public int get_i(int i){
	  return queArray[i];
	}

   public static void main(String[] args) throws IOException {
		Teque o = new Teque();
	   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	   String line ;
	   while((line=br.readLine())!=null) {
		   String[] commands = line.split(" ");
		   String command = commands[0];
		   String params = commands[1];
		   if ("push_back".equals(command)) {
		   		o.push_back(Integer.parseInt(params));
		   }else if ("push_front".equals(command)) {
			   o.push_front(Integer.parseInt(params));
		   }else if ("push_middle".equals(command)) {
			   o.push_middle(Integer.parseInt(params));
		   }else if ("get".equals(command)) {
			   String result = o.get_i(Integer.parseInt(params)) + "";
			   System.out.println(result);
		   }
	   }
	}
}


